﻿requirejs.config({
    baseUrl: ".",
    paths: {
    	zepto:"javascripts/zepto.min",
    	dingtalk:"javascripts/dingtalk",
        vue: "components/vue/vue.min",
        axios: "components/axios/axios.min",
        common: "resources/js/common"
    }
});

require(["zepto","dingtalk","vue", "axios", "common"], function (zepto,dingtalk,Vue, axios, common) {

    var vm = new Vue({
        el: "#view",
        data: {
            total: 0,
            groups: []
        },
        methods: {
            gotoRequesPoolAssignment: function (id) {
                window.location.href = "requesPoolAssignment.html?id=" + id;
            }
        }
    });

    axios.get("/incident/listByStatus?status=待分派")
        .then(function (response) {
            vm.total = response.data.length;
            var requests = response.data;
            var groups = [];
            for (var i = 0; i < requests.length; i++) {
                var index = findIndex(groups, requests[i].cus_customer_name)
                groups[index].requests.push(requests[i]);
            }
            vm.groups = groups;
        });

    var findIndex = function (groups, cus_customer_name) {
        var index = 0;
        for (; index < groups.length; index++) {
            if (groups[index].cus_customer_name == cus_customer_name) {
                return index;
            }
        }
        groups.push({
            "cus_customer_name": cus_customer_name,
            "requests": []
        })
        return index;
    }
});